<!--
Copyright Materialize, Inc. All rights reserved.

Use of this software is governed by the Business Source License
included in the LICENSE file at the root of this repository.

As of the Change Date specified in that file, in accordance with
the Business Source License, use of this software will be governed
by the Apache License, Version 2.0.
-->

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>SQL Logic Test Results</title>
    <style>
    table, th, td {
        border: 1px solid black;
        border-collapse: collapse;
    }

    th, td {
        padding: 3px 2px;
    }

    .commit {
        font-family: monospace;
    }
    </style>
    <script src="https://www.gstatic.com/charts/loader.js"></script>
</head>
<body>
    <h1>SQL Logic Test Results</h1>
    <table>
        <tr>
            <th>Commit</th>
            <th>Time</th>
            <th>Unsupported</th>
            <th>Parse failure</th>
            <th>Plan failure</th>
            <th>Unexpected plan success</th>
            <th>Wrong number of rows affected</th>
            <th>Inference failure</th>
            <th>Wrong column names</th>
            <th>Output failure</th>
            <th>Bail</th>
            <th>Success</th>
            <th>Total</th>
        </tr>
        {% for r in results %}
            <tr>
                <td class="commit">
                    <a href="https://github.com/MaterializeInc/materialize/commit/{{ r.commit }}">
                        {{ r.commit | truncate(9, true, '') }}
                    </a>
                </td>
                <td>{{ r.timestamp.strftime("%Y-%m-%d %-I:%M %p") }} UTC</td>
                <td>{{ r.unsupported }}</td>
                <td>{{ r.parse_failure }}</td>
                <td>{{ r.plan_failure }}</td>
                <td>
                    {% if r.unexpected_plan_success is none %}
                        ?
                    {% else %}
                        {{ r.unexpected_plan_success }}
                    {% endif %}
                </td>
                <td>
                    {% if r.wrong_number_of_rows_affected is none %}
                        ?
                    {% else %}
                        {{ r.wrong_number_of_rows_affected }}
                    {% endif %}
                </td>
                <td>{{ r.inference_failure }}</td>
                <td>
                    {% if r.wrong_column_names is none %}
                        ?
                    {% else %}
                        {{ r.wrong_column_names }}
                    {% endif %}
                    </td>
                <td>{{ r.output_failure }}</td>
                <td>{{ r.bail }}</td>
                <td>{{ r.success }}</td>
                <td>
                    {{ r.unsupported +
                       r.parse_failure +
                       r.plan_failure +
                       (r.unexpected_plan_success or 0) +
                       (r.wrong_number_of_rows_affected or 0) +
                       r.inference_failure +
                       (r.wrong_column_names or 0) +
                       r.output_failure +
                       r.bail +
                       r.success }}
                </td>
            </tr>
        {% endfor %}
    </table>

    <div>
        <script>
            const results = {{ results | tojson }};
            const container = document.currentScript.parentNode;

            google.charts.load("current", {"packages": ["corechart"]});
            google.charts.setOnLoadCallback(() => {
                const data = google.visualization.arrayToDataTable([
                    [
                        "Commit",
                        {role: "none"},
                        "Unsupported",
                        "Parse failures",
                        "Plan failures",
                        "Inference failures",
                        "Output failures",
                        "Bails",
                        "Successes",
                        "Unexpected plan successes",
                        "Wrong number of rows affected",
                        "Wrong column names"
                    ],
                    ...results.map(r => {
                        r[0] = r[0].substring(0, 9);
                        return r
                    })
                ]);

                const chart = new google.visualization.LineChart(container);
                chart.draw(data, {
                    height: 600,
                    isStacked: true,
                    vAxis: {logScale: true}
                });
            });
        </script>
    </div>
</body>
</html>
